package com.app.service.impl;


import com.app.common.EducationTool;
import com.app.common.ScaleTool;
import com.app.mapper.CusEducationMapper;
import com.app.mapper.IntermediaryMapper;
import com.app.model.CusEducationModel;
import com.app.model.IncubatorsModel;
import com.app.model.IntermediaryModel;
import com.app.service.CusEducationService;
import com.app.service.CustomerService;
import com.app.service.IntermediaryService;
import com.app.service.UserService;
import com.app.util.Result;
import com.app.util.StringTool;
import com.app.vo.IncubatorsVo;
import com.app.vo.IntermediaryVo;
import com.app.vo.ScaleVo;
import com.app.vo.ValueAndNameVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


/**
 * @Description:中介机构
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class IntermediaryServiceImpl implements IntermediaryService {
    @Autowired
    UserService userService;
    @Autowired
    IntermediaryMapper intermediaryMapper;

    @Override
    public int insert(IntermediaryModel model) {
        return intermediaryMapper.insert(model);
    }

    @Override
    public void update(IntermediaryModel model) {
        intermediaryMapper.updateById(model);

    }

    @Override
    public IntermediaryVo getListByModel(IntermediaryModel model) {
        QueryWrapper<IntermediaryModel> queryWrapper = new QueryWrapper<>();
        if (model.getName() != null) {
            queryWrapper.like("name", model.getName());
        }
        queryWrapper.orderByDesc("id");
        Page<IntermediaryModel> pages = new Page<>();
        pages.setCurrent(model.getPage());
        pages.setSize(model.getLimit());
        Page<IntermediaryModel> page = intermediaryMapper.selectPage(pages, queryWrapper);
        if (page == null) {
            return null;
        } else {
            for (int i = 0; i < page.getRecords().size(); i++) {
                for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
                    if (page.getRecords().get(i).getScale() != null) {
                        if (page.getRecords().get(i).getScale() == vo.getId()) {
                            page.getRecords().get(i).setScaleText(vo.getData());
                        }
                    }
                }

            }
            IntermediaryVo vo = new IntermediaryVo();
            vo.setList(page.getRecords());
            vo.setCount((int) page.getTotal());
            return vo;
        }
    }

    @Override
    public IntermediaryModel getModelById(Integer id) {
        return intermediaryMapper.selectById(id);
    }

    @Override
    public List<IntermediaryModel> getListAll() {
        return intermediaryMapper.selectList(null);
    }

    @Override
    public IntermediaryModel getListByMobile(String mobile) {
        QueryWrapper<IntermediaryModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile", mobile);
        try {
            return intermediaryMapper.selectOne(queryWrapper);
        } catch (Exception e) {
            System.out.println(e);
            return null;
        }
    }
}
